export default class Stack<T> {
  private items: T[] = []

  // 获取栈的长度
  public get length(): number {
    return this.items.length
  }

  // 判断栈是否为空
  public get isEmpty(): boolean {
    return this.length === 0
  }

  // 入栈
  public push(item: T): void {
    this.items.push(item)
  }

  // 出栈
  public pop(): T | undefined {
    return this.items.pop()
  }

  // 获取栈顶元素
  public peek(): T | undefined {
    return this.items[this.length - 1]
  }
}
